<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>Vue.extend的简写形式</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="demo"></div>

        <script type="text/javascript">
            const Hello = {
                template:`<h1>你好！</h1>`
            }
                

            const Person = {
                name:'Person',
                template:`
                    <div>
                        <Hello/>
                        <h2>人员信息</h2>
                        <h4>姓名：{{pname}}</h4>
                        <h4>年龄：{{age}}</h4>
                        <button @click="showPersonInfo">点我提示人员的信息</button>
                    </div>
                `,
                data(){
                    return {
                        pname:'圆圆的海峰',
                        age:18,
                       
                    }
                },
                methods:{
                    showPersonInfo(){
                        alert(this.pname + '-' + this.age)
                    }
                }
            }
            
            const School = {
                name:'School',
                template:`
                    <div>
                        <Hello/>
                        <h2>学校信息</h2>
                        <h4>校名：{{sname}}</h4>
                        <h4>校址：{{address}}</h4>
                        <button @click="showSchoolInfo">点我提示学校的信息</button>
                    </div>
                `,
                data() {
                    return {
                        sname:'尚硅谷',
                        address:'宏福科技园'
                    }
                },
                methods:{
                    showSchoolInfo(){
                        alert(this.sname + '-' + this.address)
                    }
                }
            }

            const App = {
                name:'App',
                template:`
                    <div>
                        <Person/>
                        <hr>
                        <School/>  
                    </div>
                `,
                components:{
                    Person,
                    School,
                },
            }

            //全局注册
            Vue.component('Hello',Hello)

            new Vue({
                el:'#demo',
                components:{App},
                template:`<App/>`
            })
            
        </script>
    </body>
</html>